const CopyWebpackPlugin = require("copy-webpack-plugin");

const { defineConfig } = require('@vue/cli-service')

const path = require("path");
const packageName = "ava-work-extension";
// 复制文件夹到指定目录
const copyFiles = [
  {
    from: path.resolve("src/manifest.json"),
    to: `${path.resolve(packageName)}/manifest.json`
  },
  {
    from: path.resolve("public"),
    to: path.resolve(packageName)
  }
];



// 复制插件
const plugins = [
  new CopyWebpackPlugin({
    patterns: copyFiles
  })
];

module.exports = defineConfig({
  // publicPath: './',
  transpileDependencies: true,
  lintOnSave: false,
  pages: {
    popup: {
      entry: `src/popup/popup.js`,
      template: `src/popup/popup.html`,
      filename: `popup.html`
    },
    iframe: {
      entry: `src/iframe/iframe.js`,
      template: `src/iframe/iframe.html`,
      filename: `iframe.html`
    },
    home: {
      entry: `src/home/home.js`,
      template: `src/home/home.html`,
      filename: `home.html`
    },
    rpmanager: {
      entry: `src/rpmanager/rpmanager.js`,
      template: `src/rpmanager/rpmanager.html`,
      filename: `rpmanager.html`
    }
  },
  productionSourceMap: false,
  outputDir: __dirname + '/' + packageName,
  configureWebpack: {
    watch: true,
    entry: {
      content: "./src/content-script/content-script.js",
      'inject-url-listener': "./src/content-script/inject-url-listener.js",
      background: "./src/background/background.js",
      popup: "./src/popup/popup.js",
      iframe: "./src/iframe/iframe.js",
      home: "./src/home/home.js",
      rpmanager: "./src/rpmanager/rpmanager.js",
    },
    output: {
      filename: "js/[name].js"
    },
    plugins,
    optimization: {
      splitChunks: false
    },
  },
  css: {
    extract: {
      filename: "css/[name].css"
    }
  },
  devServer: {
    proxy: {
      '/ipd-api': {
        target: 'http://192.168.37.236:81/',
        changeOrigin: true,
        pathRewrite: {
          '^/ipd-api': '/api'
        }
      },
      '/bing': {
        target: 'https://www.bing.com/',
        changeOrigin: true,
        secure: false,
        pathRewrite: {
          '^/bing': ''
        }
      },
      '/msn': {
        target: 'https://api.msn.cn/',
        changeOrigin: true,
        secure: false,
        pathRewrite: {
          '^/msn': ''
        }
      },
      '/baidu': {
        target: 'https://top.baidu.com/',
        changeOrigin: true,
        secure: false,
        pathRewrite: {
          '^/baidu': ''
        }
      },
      '/toutiao': {
        target: 'https://www.toutiao.com/',
        changeOrigin: true,
        secure: false,
        pathRewrite: {
          '^/toutiao': ''
        }
      },
      '/aliyuncsOss': {
        target: 'https://awork.oss-cn-beijing.aliyuncs.com/',
        changeOrigin: true,
        secure: false,
        pathRewrite: {
          '^/aliyuncsOss': ''
        }
      }
    }
  }
})